<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bai 3.7</title>
</head>

<body>
<?php
	function XuatMang($mang)
	{
		for($i=0;$i<count($mang);$i++)
		{
				$kq.=$mang[$i].",";
		}
		return $kq;
	}
	function HoanVi(&$a,&$b)
	{
		$tam=$a;
		$a=$b;
		$b=$tam;
	}
	if(isset($_POST['nhap']) && isset($_POST['gtthaythe']) &&isset($_POST['gt_canthaythe']))
	{
		$mangnhap=explode(",",$_POST['nhap']);
		$giatricanthay=$_POST['gt_canthaythe'];
		$giatrithaythe=$_POST['gtthaythe'];
		$mangcu=XuatMang($mangnhap);
		for($i=0;$i<count($mangnhap);$i++)
		{			
			if($mangnhap[$i]==$giatricanthay)	
				$mangnhap[$i]=$giatrithaythe;											
		}		
		$mangsauthaythe=XuatMang($mangnhap);
	}
?>
<form id="form1" name="form1" method="post" action="Bai3_7.php">
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr bgcolor="#990066" style="text-align: center; font-size: 24px; font-weight: bold; font-style: italic; color: #FFF;">
      <td colspan="2">THAY THẾ</td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#FF99FF">Nhập các phần tử:</td>
      <td nowrap="nowrap" bgcolor="#FF99FF"><input name="nhap" type="text" id="nhap" value="<?php echo $_POST['nhap'];?>" size="96%" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#FF99FF">Giá trị cần thay thế:</td>
      <td nowrap="nowrap" bgcolor="#FF99FF"><input name="gt_canthaythe" type="text" id="gt_canthaythe" value="<?php echo $_POST['gt_canthaythe'];?>" /></td>
    </tr>
    <tr bgcolor="#FF99FF">
      <td nowrap="nowrap">Giá trị thay thế:</td>
      <td nowrap="nowrap"><input name="gtthaythe" type="text" id="gtthaythe" value="<?php echo $_POST['gtthaythe'];?>" /></td>
    </tr>
    <tr bgcolor="#FF99FF">
      <td nowrap="nowrap">&nbsp;</td>
      <td nowrap="nowrap"><input style="background-color:#FFC" type="submit" name="button" id="button" value="Thay thế" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#FFCCFF">Mảng cũ:</td>
      <td nowrap="nowrap" bgcolor="#FFCCFF"><input name="mangcu" type="text" id="mangcu" style="background-color:#C33" value="<?php echo $mangcu;?>" size="96%" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#FFCCFF">Mảng sau khi thay thế:</td>
      <td nowrap="nowrap" bgcolor="#FFCCFF"><input name="mangsauthaythe" type="text" id="mangsauthaythe" style="background-color:#C33" value="<?php echo $mangsauthaythe;?>" size="96%" /></td>
    </tr>
    <tr style="text-align: center">
      <td colspan="2" bgcolor="#FFCCFF">(<span style="color: #C00; font-weight: bold;">Ghi chú</span>: Các phần tử trong mảng sẽ cách nhau bằng dấu &quot;,&quot;)</td>
    </tr>
  </table>
</form>
</body>
</html>